package com.kaishengit.service;

import java.util.List;

import com.kaishengit.dao.MessageDao;
import com.kaishengit.pojo.Message;
import com.kaishengit.pojo.User;
import com.kaishengit.pojo.UserGroup;

public class MessageService {
	
	private MessageDao messageDao;

	public List<Message> findICanSee(User user, UserGroup group) {
		String hql = "from Message where view is not null and (user = ? or view = 'all' or view like ? or view like ?) order by createTime desc";
		String first = "%u:" + user.getId() + "%";
        String second = "";
        if (group != null) {
            second = "%g:" + group.getId() + "%";
        }
        List<Message> messageList = messageDao.find(hql, user, first, second);
        return messageList;
	}
	
	public MessageDao getMessageDao() {
		return messageDao;
	}
	
	public void setMessageDao(MessageDao messageDao) {
		this.messageDao = messageDao;
	}
}
